<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-text">
            登录协议
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>登录协议</legend>
        </fieldset>

        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">协议标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title"   lay-verify="title"  required autocomplete="off"  value="{{$title}}"
                           placeholder="请输入标题"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">协议内容</label>
                <textarea id="content"   name="content" required   lay-verify="content"   style="display: none;"> {{$content}}</textarea>
            </div>


            <div id="test12" class="demo-tree-more"></div>
            <div class="layui-form-item">

                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                </div>
            </div>
        </form>

    </div>
</div>

<script src="/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="/js/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'layedit'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 1) {
                    return '角色至少得1个字符啊';
                }
            }
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //创建一个编辑器
        layedit.set({
            uploadImage: {
                url: '/admin/upload/img' //上传接口
                ,type: 'post' //默认post
            }
        });
        var editIndex = layedit.build('content',{
            height: 180,
        });

        //自定义验证规则
        form.verify({
            content: function (value) {
                layedit.sync(editIndex);
            }
        });
        //监听提交
        var url = '/admin/agreement/save';
        form.on('submit(demo1)', function (data) {
            var formData = data.field;
            // alert(formData);
            // console.log(formData);
            // formData.field.content =layedit.getContent(editIndex);
         // console.log(formData);
         //
         //    return false;
            $.ajax({
                url: url,
                data: formData,
                method: 'post',
                headers: {
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                },
                success: function (resp, status, xhr) {
                    if (xhr.status == 200) {
                        layer.msg(resp.msg,{icon: 6});
                    }
                },
                error: function (re) {
                    layer.msg(re.responseJSON.msg, {icon: 2});

                }
            })
            return false;
        });

    });

</script>

</body>
</html>